// pages/maintenance/maintenance.js
var app = getApp();
var util = require('../../utils/util.js');
var applet_park_api_url = app.globalData.applet_park_api_url;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    currenttab: '',
    showModal: false,
    items: [],
    type: "",
    assignorId: '',
    consignorId: '',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (options.type) {
      this.data.type = options.type
    }
    if (options.assignorId) {
      this.data.assignorid = options.assignorId
    }
    if (options.consignorId) {
      this.data.consignorid = options.consignorId
    }

    this.setData(this.data);

  },
  packBp(e) {
    this.setData({
      currenttab: e.currentTarget.dataset.index
    })
  },
  testSubmit(e) {
    var self = this;
    var openId = wx.getStorageSync("OPENID");
    var fId = e.detail.formId; //获取formId
    
    wx.request({
      url: 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wxcc80ff4f9e7ee858&secret=88cdd694e5804167c07f5b89b5a56d20',
      method: 'GET',
      success: function (res) {
        

        var d = {
          "keyword1": {
            "value": "00273",
            "color": "#4a4a4a"
          },
          "keyword2": {
            "value": "腾讯早餐店",
            "color": "#9b9b9b"
          },
          "keyword3": {
            "value": "66元",
            "color": "#9b9b9b"
          }

        };
        
        wx.request({
          url: 'https://api.weixin.qq.com/cgi-bin/message/wxopen/template/uniform_send?access_token=' + res.data.access_token,
          // header: {
          //   'content-type': 'Content-Type: application/json;',
          // },
          data: {
            touser: openId,
            template_id: "BEaKeDwRS2aPA0xfsrbSlxh7NfFeM7rSDk5wd70_WNs", //换成你申请的模板消息id，  
            page: "pages/index/index",
            form_id: e.detail.formId,
            data: d

          },
          method: 'POST',
          success: function (res) {
            
          },
          fail: function (err) {
            
          }
        })
      },
    })
  },

  formSubmit: function (e) {
    var that = this
    
    
    wx.request({
      url: "https://xxx/mobiletplus/index.php?act=login&op=send_wx",
      data: {
        "form_id": e.detail.formId,
        "customer_id": that.data.customer_id
      },
      method: 'POST',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
        //util.showSuccess("设置成功")
        //

      },
      fail: function (e) {
        //util.showError("设置失败".e)
      }
    })
  },

  openzp: function () {
    this.setData({
      showModal: true
    })
  },

  preventTouchMove: function () {

  },


  go: function () {
    this.setData({
      showModal: false
    })
  },
  loadData() {
    this.setData({
      title: '数据正在加载',
    })
    let that = this;
  

    let id = wx.getStorageSync("id");
    if (!id) {
      return
    }
    
    wx.request({
      url: applet_park_api_url + '/api/notifications/application',
      data: {
       
        assignorId: id,
        type: 2
      },
      success(res) {
        
        
        if (res.data.code == 0) {
          // for (var row of res.data.data) {
          //   if (row.planningTime) {
          //     row.planningTime = util.ymdFormat(row.planningTime);
          //   }
          //   that.data.items.push(row);
          // }
          that.data.items = res.data.data;

          if (that.data.items.length == 0) {
            that.setData({
              title: '暂无更多数据',
            })
          } else {
            that.setData({
        
              title: ''
            })
          }
          that.setData(that.data);
        } else {
          wx.showToast({
            title: '网络异常',
          })
        }
      },
      fail(res) {
        wx.showToast({
          title: res.data,
        })
      }
    })
  },
  goToDetail() {
    // pages / maintenanceDetail / maintenanceDetail
    wx.navigateTo({
      url: '../maintenanceDetail/maintenanceDetail',
    })
  },
  goexamine(e) {
    // wx.navigateTo({
    //   url: '../tenantexamine/tenantexamine',
    // })
    let type = e.currentTarget.dataset.type;
    let id = e.currentTarget.dataset.id;
    let todoid = e.currentTarget.dataset.todoid;
    let todoStatus = e.currentTarget.dataset.todostatus;
    let assignorid = e.currentTarget.dataset.assignorid;
    let apply = e.currentTarget.dataset.myapply;
    if (type == 1) {
      wx.navigateTo({
        url: '../Employe_examine/Employe_examine?id=' + id + '&todoid=' + todoid + "&todoStatus=" + todoStatus + "&assignorid=" + assignorid + '&apply=' + apply,
      })
    }
    if (type == 2 || type == 3) {
      wx.navigateTo({
        url: '../tenantexamine/tenantexamine?id=' + id + '&todoid=' + todoid + "&todoStatus=" + todoStatus + "&assignorid=" + assignorid + '&apply=' + apply,
      })
    }

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.loadData();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    wx.stopPullDownRefresh();
    this.loadData();
    wx.showToast({
      title: '刷新成功',
      icon: 'success',
      duration: 2000
    })
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})